
$(function() {
    admin.userHonor.init();
});
Namespace('admin.userHonor',{
    init:function() {
        easyui.util.initDatagrid('#datagrid',{
            onDblClickRow:function() {
                //admin.user.update();
            }
        });
    },
    query:function() {
        if(!$('#query-form').form('validate')) return;
        var data=$('#query-form').form('jsonObject');
        $('#datagrid').datagrid('load',data);
    },
    add:function() {
		top.addTab("1",'村民荣誉制度', contextPath+'/admin/user/userHonor/add');
	},
	doAdd:function() {
		 if(!$('#data-form').form('validate')) return;
	        var data=$('#data-form').form('jsonObject');
	        $('#saveButton').attr('disabled','disabled');
	        $('#datagrid').datagrid('loading');
	        $.post(contextPath + '/admin/user/userHonor/doAdd', data, function (result) {
	            $('#saveButton').removeAttr('disabled');
	            $('#datagrid').datagrid('loaded');
	            if (result.code == 0) {
	                top.showInfo('添加村民荣誉制度成功');
	                top.addTab('','村民荣誉制度列表', contextPath+'/admin/user/userHonor/list');
	            } else {
	                top.showInfo("添加村民荣誉制度失败，原因："+result.msg);
	            }
	        });
	},
    detail:function(id) {
        if (id != null) {
            top.addTab(id,'userHonor详情', contextPath+'/admin/userHonor/detail?id=' + id);
        }
    },
    del:function(id) {
		  $.post(contextPath + '/admin/user/userHonor/del', {id:id}, function (result) {
	            $('#datagrid').datagrid('loaded');
	            if (result.code == 0) {
	                top.showInfo('删除村民荣誉制度成功');
	                top.addTab('','村民荣誉制度列表', contextPath+'/admin/user/userHonor/list');
	            } else {
	                top.showInfo("删除村民荣誉制度失败，原因："+result.msg);
	            }
	        });
	},
	audit:function(id) {
		top.addTab(id,'村民荣誉制度', contextPath+'/admin/user/userHonor/audit?id=' + id);
	},
	doAudit:function() {
		 if(!$('#data-form').form('validate')) return;
	        var data=$('#data-form').form('jsonObject');
	        $('#auditButton').attr('disabled','disabled');
	        $('#datagrid').datagrid('loading');
	        $.post(contextPath + '/admin/user/userHonor/doAudit', data, function (result) {
	            $('#saveButton').removeAttr('disabled');
	            $('#datagrid').datagrid('loaded');
	            if (result.code == 0) {
	                top.showInfo('编辑村民荣誉制度成功');
	                top.addTab('','村民荣誉制度列表', contextPath+'/admin/user/userHonor/list');
	            } else {
	                top.showInfo("编辑村民荣誉制度失败，原因："+result.msg);
	            }
	        });
	},
    upload:function(count) {
		//$("#filedata-form").submit();
		$('#filedata-form'+count).form('submit',{
			onSubmit: function(){
				if ($('#uploadkey'+count).val()=='') {
					top.showInfo('请选择图片!');
					return false;
				}
			}, 
			success:function(result){
				result = JSON.parse(result);
				if (result.code=='0') {
					if(count==1){
						$('#img').val(result.map.uploadResults[0].filePath);
					}
					if(count==2){
						$('#certificate').val(result.map.uploadResults[0].filePath);
					}
					$('#showpic'+count).html('<img src="http://img.wanrenhui.cn'+result.map.uploadResults[0].filePath+'@150w_150h_2o">');
				}
			}
		});
		
	}
});